﻿using System.Collections.Generic;
using System.Linq;
using Unread.Business.Data.Opml.Model;

namespace Unread.Business.Models
{
    public partial class Feed
    {
        public static List<Feed> MapOutlinesToFeeds(List<Outline> outlines)
        {
            return (from outline in outlines
                    select new Feed
                    {
                        Id = outline.Id,
                        Title = outline.Title,
                        Subtitle = outline.Subtitle,
                        SyndicationUri = outline.XmlUrl,
                        Website = outline.HtmlUrl,
                        Image = outline.Image,
                        LastRead = outline.LastRead
                    }).ToList();
        }

        public static Outline MapFeedToOutline(Feed feed)
        {
            return new Outline
            {
                Id = feed.Id,
                Title = feed.Title,
                Text = feed.Title,
                Subtitle = feed.Subtitle,
                XmlUrl = feed.SyndicationUri,
                HtmlUrl = feed.Website,
                Image = feed.Image,
                LastRead = feed.LastRead,
                Type = "rss"
            };
        }

        public static List<Outline> MapFeedsToOutlines(List<Feed> feeds)
        {
            return (from feed in feeds
                    select MapFeedToOutline(feed)).ToList();
        }
    }
}
